<template>
  <div>
    <div class="body fade-show" v-if="!initLoading">
      <div class="shop-head-bg">
        <image mode="aspectFill" :src="shopDetail.shop_image"></image>
      </div>
      <div style="height: 360rpx"></div>
      <div class="detail-box">
        <div class="detail-head">
          <image mode="aspectFill" :src="shopDetail.shop_logo"></image>
          <div class="ml10 shop-name">
            <div class="shop-name-text fw">{{ shopDetail.shop_name }}</div>
          </div>
        </div>
        <div class="detail-item flex between" @click="onPhone">
          <div class="detail-item-left flex">
            <div class="text-grey icon icon-dianhua"></div>
            <div class="ml10">{{ shopDetail.phone }}</div>
          </div>
          <div class="detail-item-right">联系</div>
        </div>
        <div class="detail-item flex between" @click="onLocation">
          <div class="detail-item-left flex items-center">
            <div class="text-grey icon icon-dingwei1"></div>
            <div class="ml10">
              <div>
                {{ shopDetail.region.city }}{{ shopDetail.region.province
                }}{{ shopDetail.region.region }}
              </div>
              <div>{{ shopDetail.address }}</div>
            </div>
          </div>
          <div class="detail-item-right">导航</div>
        </div>
        <div class="detail-item flex">
          <div class="detail-item-left items-center">
            <div class="text-grey fz-small">营业时间</div>
            <div class="mt5">
              {{ shopDetail.start_time }} - {{ shopDetail.end_time }}
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <init-load v-if="initLoading"></init-load>
</template>

<script setup lang="ts">
import { onLoad } from "@dcloudio/uni-app";
import { ref, getCurrentInstance, onMounted } from "vue";
import { getShopDetail } from "@/api/shop";
import { Result, ResultError } from "@/types";

const {
  proxy,
  proxy: { $utils },
} = getCurrentInstance() as any;

const shopDetail = ref<any>({});

const initLoading = ref<boolean>(true);

const shopId = ref<number>(0);

const toInit = () => {
  getShopDetail({
    id: shopId.value,
  })
    .then((res: Result) => {
      shopDetail.value = res.data;
      initLoading.value = false;
    })
    .catch((err: ResultError) => {
      $utils.errorMsg(err);
    });
};

onLoad((options: any) => {
  shopId.value = options.id || 0;
  toInit();
});

const onPhone = () => {
  uni.makePhoneCall({
    phoneNumber: shopDetail.value.phone,
  });
};

const onLocation = () => {
  uni.openLocation({
    //​使用微信内置地图查看位置。
    latitude: parseFloat(shopDetail.value.coordinate.latitude), //要去的纬度-地址
    longitude: parseFloat(shopDetail.value.coordinate.longitude), //要去的经度-地址
    name: shopDetail.value.shop_name,
    address: shopDetail.value.address,
  });
};
</script>


<style scoped>
.shop-head-bg {
  width: 100%;
  height: 380rpx;
  position: fixed;
  top: 0;
  left: 0;
  z-index: -1;
}
.shop-head-bg image {
  width: 100%;
  height: 380rpx;
}
.detail-box {
  width: 100%;
  border-top-right-radius: 20rpx;
  border-top-left-radius: 20rpx;
  background: #f9f9f9;
  padding: 20rpx 0;
}
.detail-head {
  display: flex;
  justify-content: flex-start;
  background: #ffffff;
  padding: 20rpx;
  padding-bottom: 20rpx;
}
.detail-head image {
  width: 120rpx;
  height: 120rpx;
  border-radius: var(--base-radius-default);
}

.shop-name {
  width: calc(100% - 140rpx);
  display: block;
  align-items: center;
}

.detail-item {
  margin-top: 20rpx;
  background: #ffffff;
  padding: 30rpx 20rpx;
  align-items: center;
}
.detail-item-left .icon {
  font-size: 20px;
}
.detail-item-right {
  color: var(--base-blue);
}
</style>